import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-31
 * Time: 21:01
 */
//15 22 51 31 99 ,输出 22,31,15,51,99
public class Test2 {
    public static void main(String[] args) {
//        int a = getNum(134);
//        System.out.println(a);
        int[] arr = new int[]{15,22,51,31,99};

        int[] arr1= new int[5];

        for(int i = 0; i < 5; i++) {
            arr1[i] = getNum(arr[i]);
//            System.out.println(arr1[i]);
        }

//        for(int i = 0; i < 5; i++) {
//            System.out.println(arr1[i]);
//        }

        Integer[] index = new Integer[5];

        for(int i = 0; i < 5; i++) {
            index[i] = i;
        }

        Arrays.sort(index,(i,j)->{
            return arr1[i]-arr1[j];
        });

        int[] ret = new int[5];
        for(int i = 0; i < 5; i++) {
            ret[i] = arr[index[i]];
            System.out.println(ret[i]);
        }
    }
    public static int getNum(int num) {
        int sum = 0;
        while(num != 0) {
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
}


